﻿using UnityEngine;
using System.Collections;

/// <summary>
/// Script created by John Ernest to automate a sound that
/// does not start automatically and the object dies once
/// it plays once so that you can instantiate multiple 
/// instances of the same audio clip on different audio channels
/// rather than have one audio source that plays over the
/// same sound. Feel free to use this in your projects.
/// </summary>
public class InstantiatedSoundScript : MonoBehaviour {

	public AudioSource InstantiatedSoundSource;
	bool started = false;
	// Use this for initialization
	void Start () {
	
	}

	public void StartSound()
	{
		started = true;
		
		InstantiatedSoundSource.Play();
	}
	
	// Update is called once per frame
	void Update () {
		if (started && !InstantiatedSoundSource.isPlaying) {
			Destroy(this.gameObject);
		}
	}
}
